/////////////////////////////////////////////////////////////////////
//
//  Tackle - A Scrum Tracking Web Site Solution
//  Original Copyright ?2007 Microsoft Corp.  All rights reserved.
//  Released under Microsoft Permissive License (Ms-PL)
//  http://www.codeplex.com/Tackle/Project/License.aspx
//
/////////////////////////////////////////////////////////////////////

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Error : System.Web.UI.Page
{
    // reads dev mail address from Web.config and returns HTML string for mailto link.
    protected string GetStringForMailToDevTeam()
    {
        string mailAddress = ConfigurationManager.AppSettings["DevMailAddress"];
        if (mailAddress == null)
        {
            mailAddress = "&lt;Error! DevMailAddress isn't set&gt";
        }
        return "<a href=\"mailto:" + mailAddress + "\">" + mailAddress + "</a>";
    }

    // reads admin mail address from Web.config and returns HTML string for mailto link.
    protected string GetStringForMailToAdmin()
    {
        string mailAddress = ConfigurationManager.AppSettings["AdminMailAddress"];
        if (mailAddress == null)
        {
            mailAddress = "&lt;Error! AdminMailAddress isn't set&gt";
        }
        return "<a href=\"mailto:" + mailAddress + "\">" + mailAddress + "</a>";
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        // display appropriate message according to the error code in the query string
        switch ((TackleError.ErrorCode)Convert.ToInt32(Request.QueryString["ErrorCode"]))
        {
            case TackleError.ErrorCode.SiteAccessDenied:
                lblErrorMessage.Text = "Access denied. You do not have permission to access this site. "
                    + "Please email the site administrators at " + GetStringForMailToAdmin() + " to request access.";
                hlToDefault.Visible = false;
                break;
            case TackleError.ErrorCode.PageAccessDenied:
                lblErrorMessage.Text = "Access denied. You do not have permission to access this resource or page. "
                    + "Please email the site administrators at " + GetStringForMailToAdmin() + " to request access. "
                    + "Alternatively, contact the scrum master for the team information you wish to access.";
                break;
            case TackleError.ErrorCode.SessionTimeOut:
                lblErrorMessage.Text = "Session Timeout. Your session has been inactive for a period of time and has now timed out. "
                    + "Please return to the home page to begin a new session.";
                break;
            case TackleError.ErrorCode.CustomErrorMessage:
                lblErrorMessage.Text = "Development Error. You have found a bug in the Tackle site. "
                    + "Please email the site administrators at " + GetStringForMailToDevTeam()
                    + " and supply a description of the action you were taking and the URL you were trying to reach. "
                    + "Please also copy and paste the text from below into the email. Thanks!<br/><pre>"
                    + (string)Session["errorInfo"] + "</pre>";
                break;
            default:
                lblErrorMessage.Text = "Unknown error.";
                break;
        };
    }
}
